package com.cat.service;

import com.cat.common.ImgState;
import com.cat.common.SpiderUtils;
import com.cat.mybatis.dao.ImgSourceDao;
import com.cat.mybatis.domain.ImgSourceDO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 下载图片逻辑
 *
 * @author xiemh
 * @date 2018/12/18 21:25
 * @since v1.0.0
 */
@Service
public class DownloadService {
    @Resource
    ImgSourceDao imgSourceDao;

    public void downloadImgSourceDO() {
        List<ImgSourceDO> list = imgSourceDao.selectByState(ImgState.Analyzed.getCode());

        for(ImgSourceDO i : list){
            SpiderUtils.downloadPicture(i.getSmallUrl(), i.getSmallPath());
            SpiderUtils.downloadPicture(i.getUrl(), i.getPath());
            imgSourceDao.updateState(ImgState.Downloaded.getCode(),i.getImgId());
        }
    }
}
